package com.jy.adscm.system.controller;

import com.jy.adscm.annotation.AdscmLogger;
import com.jy.adscm.bean.system.JyDept;
import com.jy.adscm.bean.system.JyRole;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.security.support.SimpleResponse;
import com.jy.adscm.system.service.JyDeptService;
import com.jy.adscm.system.service.JyRoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yyy
 * @ClassName AdscmDeptController
 * @Description 组织机构Controller
 * @date 2018/8/2 17:40
 */
@RestController
@CrossOrigin
@RequestMapping("/adscm/system/dept")
public class AdscmDeptController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    JyDeptService jyDeptService;

    /**
     * 增加部门
     * @param dept
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/addDept")
    @AdscmLogger("增加部门")
    public SimpleResponse addDept(JyDept dept) throws AdscmSystemException{

        jyDeptService.insert(dept);

        return new SimpleResponse("200","增加部门成功",dept);
    }

    /**
     * 修改部门
     * @param dept
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/editDept")
    @AdscmLogger("修改部门")
    public SimpleResponse editDept(JyDept dept) throws AdscmSystemException{

        jyDeptService.update(dept,null);

        return new SimpleResponse("200","修改部门成功",dept);
    }

    /**
     * 删除部门
     * @param deptId
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/delDept/{deptId}")
    @AdscmLogger("删除部门")
    public SimpleResponse delDept(@PathVariable int deptId) throws AdscmSystemException{

        jyDeptService.delDept(deptId);

        return new SimpleResponse("200","删除部门成功",null);
    }

    /**
     * 查询部门
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getAllDept")
    @AdscmLogger("查询所有部门")
    public SimpleResponse getAllDept() throws AdscmSystemException{

        List<JyDept> allDept = jyDeptService.getAllDept();

        return new SimpleResponse("200","查询所有部门成功",allDept);
    }

}
